home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / Drag_on Modules / hAWK programs / $ClipMultiToInline < prev    next >
Encoding:
Text File  |  1995-08-05  |  1.7 KB  |  70 lines  |  [TEXT/KEEN]

  1. #$ClipMultiToInline: change /*...*/ comment to
  2. # one-line style // comments. Usage: run this hAWK program,
  3. # Copy the full comment, wait for the menu bar flash,
  4. # then Paste. NOTE does only one comment at a time.
  5.  
  6. BEGIN {
  7.     clipCharsToWatch = 32;
  8.     while (1) # run until <Command><period>...
  9.         {
  10.         # see if clipboard has changed
  11.         if ((newClip = getclip(clipCharsToWatch)) != oldClip)
  12.             {
  13.             oldClip = newClip;
  14.             # a comment start is used as the trigger
  15.             if (index(newClip, "/*"))
  16.                 ChangeComment()
  17.             }
  18.         }
  19.     }
  20.  
  21. function ChangeComment(            fullClip, numLines, lines, outClip, out, i, addReturn)
  22.     {
  23.     fullClip = getclip(); # gets calling editor's private clip
  24.     numLines = split(fullClip, lines, "\r");
  25.     # with "split", the last line will be empty if the last
  26.     # character copied was a return.
  27.     if (lines[numLines] == "")
  28.         {
  29.         --numLines;
  30.         addReturn = 1;
  31.         }
  32.     else
  33.         addReturn = 0;
  34.     # Put lines to out, altering comment form
  35.     for (i = 1; i <= numLines; ++i)
  36.         {
  37.         # determine leading white space (RLENGTH)
  38.         match(lines[i], /^[ \t]+/);
  39.         if (i == 1)
  40.             {
  41.             sub(/\/\*[ ]?/, "", lines[i]);
  42.             }
  43.         if (i == numLines)
  44.             {
  45.             sub(/[ ]?\*\//, "", lines[i]);
  46.             }
  47.         if (RLENGTH >= 1 && RSTART == 1)
  48.             {
  49.             if (i < numLines || addReturn)
  50.                 out = out substr(lines[i], 1, RLENGTH) "// " substr(lines[i], RLENGTH+1) "\r";
  51.             else
  52.                 out = out substr(lines[i], 1, RLENGTH) "// " substr(lines[i], RLENGTH+1);
  53.             }
  54.         else
  55.             {
  56.             if (i < numLines || addReturn)
  57.                 out = out "// " lines[i] "\r";
  58.             else
  59.                 out = out "// " lines[i];
  60.             }
  61.         }
  62.     
  63.     # send the result back to the calling editor's clip
  64.     putclip(out);
  65.     # update "oldClip"
  66.     oldClip = substr(out, 1, 32);
  67.     # flash menu bar to signal something happened
  68.     beep(0);
  69.     }
  70.